package com.lucker.controller.recommend;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lucker.common.model.Algorithm;
import com.lucker.controller.BaseController;
import com.lucker.ds.model.RecommendAlgorithm;
import com.lucker.framework.constant.ResponseBaseModel;
import com.lucker.framework.constant.ResponseResultModel;
import com.lucker.service.recommendalgorithm.RecommendAlgorithmService;
import com.lucker.service.recommendplan.RecommendPlanService;

@Controller
@RequestMapping(value = "recommend")
public class RecommendController extends BaseController {
	
	@Autowired
	RecommendPlanService recommendPlanService;
	
	@Autowired
	RecommendAlgorithmService recommendAlgorithmService;
	
	
	
	@RequestMapping(value="/allplan",method = RequestMethod.POST)
	public @ResponseBody ResponseEntity<?> allplan(HttpServletRequest request,@RequestBody Map<String,Object> paramMap) {
		try {
			
			
			List<Map<String, Object>> retList = recommendPlanService.getAllPlay(request.getHeader("caiType"));
			return new ResponseEntity<>(new ResponseResultModel<List<Map<String, Object>>>(retList),HttpStatus.OK);
		}catch (Exception e) {
			getLoger().error("查询失败: {},{}",e.getMessage(),e);
			return new ResponseEntity<>(new ResponseBaseModel(29001,e.getMessage()), HttpStatus.OK);
		}
		
		
	} 

	
	@RequestMapping(value="/algorithm",method = RequestMethod.POST)
	public @ResponseBody ResponseEntity<?> algorithm(HttpServletRequest request,@RequestBody Map<String,Object> paramMap) {
		try {
			List<Algorithm> alist = new ArrayList<Algorithm>();
			RecommendAlgorithm hm = new RecommendAlgorithm();
			List<RecommendAlgorithm> list = recommendAlgorithmService.queryAll(hm);
			for(RecommendAlgorithm re : list) {
				Algorithm hms = new Algorithm();
				hms.setAiName(re.getRecommendAlgorithmName() );
				hms.setAlgorithmType(Integer.valueOf(String.valueOf(re.getId())));
				hms.setImgUrl(re.getRecommendAlgorithmPic());
				hms.setX(50);
				hms.setY(10);
				hms.setLastUserSelelctN(10);
				hms.setLastPlanN(100);
				alist.add(hms);
				
			}
			return new ResponseEntity<>(new ResponseResultModel<List<Algorithm>>(alist),HttpStatus.OK);
			
		}catch (Exception e) {
			getLoger().error("查询失败: {},{}",e.getMessage(),e);
			return new ResponseEntity<>(new ResponseBaseModel(29001,e.getMessage()), HttpStatus.OK);
		}
		
		
	} 
	
	
	

}
